// appsplus_jinglian/pages/search/search.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    city:'',
    attractions: '',
    searchlist: [],
    show: false,
    search_history:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({
      city: options.area
    })
  },
  city: function () {
    wx.switchTab({
      url: '../ticket/ticket'
    })
  },
  getValue: function (e) {
    this.setData({
      attractions: e.detail.value
    })
  },
  gotodetail: function (e) {
    var tid = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../../pages/detail/detail?id=' + tid,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  searchBtn: function (e) {
    var that = this
    console.log(this.data)
    app.util.request({
      'url': 'entry/wxapp/information',
      'cachetime': '30',
      data: {
        area: this.data.city,
        attractions: this.data.attractions,
        // column_type: 1
      },
      success: function (res) {
       var historylist =  that.data.search_history;
       var keyword = this.data.attractions
       if (historylist.indexOf(keyword) > -1) {
         //则包含该元素
        
      }else{
         historylist.push(keyword)
         that.setData({
           search_history: historylist.reverse()
         })
      }
       

        console.log(res.data)
        if (res.data.status) {
          var ret = res.data
          that.setData({
            searchlist: ret.data,
            show: false
          })
        }else{
          that.setData({
            searchlist: [],
            show: true
          })
        }
      }
    });
  }
})
// function searchBtn () {
//   console.log('123')
  
// }